"""
@version:python3
@author:ll
@file:03-QObject-信号的操作.py
@time:2022/2/8 2:28
"""
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):  # 添加子控件以及子控件的配置操作
        self.QObject_connect()

    def QObject_connect(self):
        self.obj = QObject()
        # obj.destroyed()
        # obj.objectNameChanged()
        # def destroy_cao(obj):
        #     print("信号被释放了",obj)
        # self.obj.destroyed.connect(destroy_cao)
        # del self.obj

        def obj_name_cao(name):
            print("对象名称发生了改变",name)


        def obj_name_cao2(name):
            print("对象名称发生了改变2",name)
        self.obj.objectNameChanged.connect(obj_name_cao)
        self.obj.objectNameChanged.connect(obj_name_cao2)

        print(self.obj.receivers(self.obj.objectNameChanged))

        self.obj.setObjectName("XXX")



        # print(self.obj.signalsBlocked(),"1")
        # # self.obj.objectNameChanged.disconnect()
        # self.obj.blockSignals(True) # 临时阻断连接
        # self.obj.setObjectName("OOO")
        #
        # print(self.obj.signalsBlocked(),"2")
        # self.obj.blockSignals(False)
        #
        # print(self.obj.signalsBlocked(),"3")
        #
        # self.obj.setObjectName("XXOO")


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    window = Window()
    window.show()

    sys.exit(app.exec_())
